/*
 * Copyright (c) 2016 zhangcm. All Rights Reserved.
 */
package com.jnzc.ocr.serv.shop.api.impl;

import com.jnzc.ocr.common.utils.DateUtils;
import com.jnzc.ocr.serv.shop.api.ShopMainApi;
import com.jnzc.ocr.serv.shop.entity.ShopMain;
import com.jnzc.ocr.serv.shop.service.ShopMainService;
import com.jnzc.ocr.serv.system.api.SysNoApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangcm
 * @version 1.0, 2017/8/31
 */
@RestController
public class ShopMainApiImpl implements ShopMainApi {

    @Autowired
    private ShopMainService shopMainService;

    @Autowired
    private SysNoApi sysNoApi;

    @Override
    public ShopMain find(@RequestParam("id") Long id) {
        return shopMainService.find(id);
    }

    public ShopMain insert(@RequestBody ShopMain obj) {
        String no = sysNoApi.getNextShopNo(obj.getCompanyId());
        obj.setNo(no);
        obj.setCreateTime(DateUtils.getNow());
        shopMainService.insertOne(obj);
        return obj;
    }

    @Override
    public ShopMain update(@RequestBody ShopMain obj) {
        shopMainService.updateOne(obj);
        return obj;
    }

    @Override
    public List<ShopMain> listByCompanyId(Long companyId) {
        return shopMainService.listByCompanyId(companyId);
    }
}
